Repository navigation
export: mdl export erwin — XSD-valid erwin XML that round-trips via the importer - #60
Merged
Merged
Conversation
…he importer The inverse of 'mdl import erwin'. Teams that live in erwin Data Modeler can push a Modelith-authored or reverse-engineered model back out as erwin XML. - emit_erwin(model, *, naming) in packages/emit-erd (pure Model->str), mirroring the importer's reads in reverse. Undoes the importer's asymmetries: folds the conceptual+logical split back into one <Entity> (Name=display, Physical_Name=raw); re-emits each Category as subtype <Relationship Type=Subtype_*> with a discriminator; from=child/many, to=parent/one; PK key-group membership drives role. Mints stable erwin GUIDs from ULIDs so output is reproducible. - Validates against the real erwin XSD: root <erwin FileVersion=9.8.0000 Format=erwin> -> namespaced <Model id> with required ModelEnvProps/ModelProps. (9.8.00 is INVALID — the pattern needs 4 build digits.) - Opt-in team naming convention via export.erwin.naming in mdl-project.yaml (ErwinNaming/ ExportConfig in ir.py), off by default = verbatim. Rewrites LOGICAL/display names only; Physical_Name always stays the raw snake identifier. - CLI: 'mdl export erwin -m <model> -o <file>', mirroring export dbml. Verified end to end: import sample.erwin.xml -> export -> xmllint --schema validates -> re-import -> mdl validate passes, counts/keygroups/category/verb-phrases equivalent. 11 new tests (XSD validity, round-trip equivalence, key-group member order, category+discriminator, verb phrases, naming convention, reproducibility). Full suite 1025 passed. Note: real erwin Data Modeler open-ability is out of scope (unverifiable without erwin); the target is the published XSD + our importer. The strict XSD models key-group membership opaquely (Built_In_Id); we emit the importer-readable Attribute_Ref form, which the XSD still accepts.
The round-trip test only checked subject-area names/counts, not that each area keeps its member entities. Membership is stored as conceptual-entity ids and travels through export as a Ref_Array, so it's the part most likely to silently drop. Add a test resolving each area's members back to entity names and asserting equality across export->reimport. Verified: the sample's 'Trading' area keeps [counterparty, trade].
dbose
added a commit
that referenced
this pull request
Nov 1, 2026
0.7.2 -> 0.8.0 (minor). Ships 'mdl export erwin': XSD-valid erwin XML that round-trips via the importer (PR #60), plus the opt-in export.erwin.naming model-config block. New user-facing command + config surface, so a minor bump per the versioning rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The inverse of
mdl import erwin: export a Modelith model to erwin XML. Teams that live in erwin Data Modeler can push a Modelith-authored or reverse-engineered model back out.Guarantees (both verified end to end)
erwin/ERwinSchema.xsd— root<erwin FileVersion="9.8.0000" Format="erwin">→ namespaced<Model id>with the requiredModelEnvProps/ModelProps, every object with anidand its*Propschild. (9.8.00is INVALID — the pattern needs 4 build digits.)How
emit_erwin(model, *, naming) -> strinpackages/emit-erdmirrors the importer's reads in reverse, undoing its asymmetries:<Entity>(Name= display,Physical_Name= raw snake);Categoryas subtype<Relationship Type="Subtype_*">with a discriminator;from= child/many side,to= parent/one side; PK key-group membership drivesrole.Opt-in team naming via
export.erwin.naminginmdl-project.yaml(ErwinNaming/ExportConfiginir.py), off by default = verbatim. Rewrites LOGICAL/display names only (underscore→space, title/upper/lower);Physical_Namealways stays the raw identifier. (erwin does not enforce naming at the XSD level — confirmed — so it's the exporter's job.)CLI:
mdl export erwin -m <model> -o <file>, mirroringexport dbml.Tests
12 new (10 emitter + 2 CLI): XSD validity, FileVersion/skeleton guard, round-trip equivalence, key-group member order, category+discriminator, verb phrases, subject-area membership, naming convention (logical-only, physical untouched), reproducibility, CLI write + config path. Full suite 1025 passed; ruff clean.
Scope / notes
Built_In_Id) but tolerates the importer-readable<Attribute_Ref>form, so we emit that and satisfy both goals.erwin/*.xsdis gitignored (reference/validation only); the XSD-validity test skips gracefully when the XSDs orxmllintare absent, so CI without them still runs the round-trip tests.